﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class up_change : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["name"] == null)
        {
            Response.Redirect("~/error.aspx?");
        }
        if (Session["power"].ToString() != "超级管理员")
        {

            Response.Redirect("~/PowerError.aspx?");
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/index.aspx?");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim() == "" || DropDownList1.SelectedValue == "")
        {
            Response.Write("<script>alert('请填写完整信息!')</script>");
        }
        else
        {
            SqlConnection myConn = GetConnection();
            myConn.Open();
            string sqlSTR = "select * from [Users] where UID='" + TextBox1.Text + "'";
            SqlCommand myCMD = new SqlCommand(sqlSTR, myConn);

            if (myCMD.ExecuteScalar() != null)
            {
                string sqlStr = "update [Users] set UPower ='" + DropDownList1.SelectedValue + "' where UID='" + TextBox1.Text + "' ";
                SqlCommand myCmd = new SqlCommand(sqlStr, myConn);
                myCmd.ExecuteNonQuery();
                myConn.Close();
                Response.Redirect("~/success.aspx?");
            }
            else
                Response.Write("<script>alert('用户名不存在!')</script>");
        }
    }
    public SqlConnection GetConnection()
    {
        string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }
}